/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cas.util;

import com.cas.dbaccess.CASDBAccessfactory;
import com.cas.hibernate.entity.CasUser;

/**
 *
 * @author suraj
 */
public class CASUtil {

    public static String generateHash(String text) {
        return BCrypt.hashpw(text, BCrypt.gensalt());
    }

    public static boolean checkHash(String text, String hash) {
        return BCrypt.checkpw(text, hash);
    }

    public static void main(String[] args) {
        System.out.println(BCrypt.hashpw("doctor", BCrypt.gensalt()));
        System.out.println(BCrypt.hashpw("patient", BCrypt.gensalt()));
        System.out.println(BCrypt.hashpw("user", BCrypt.gensalt()));
        System.out.println(BCrypt.hashpw("ss", BCrypt.gensalt()));
        System.out.println(BCrypt.hashpw("dd", BCrypt.gensalt()));
        System.out.println(BCrypt.hashpw("u1", BCrypt.gensalt()));

        CasUser user = new CasUser();
        user.setUserId("ss");
        user.setPassword("ss");
        CasUser d = CASDBAccessfactory.getCASDbAccess().validateUser(user);
        System.out.println(d == null);
        user.setPassword("ss1");
        d = CASDBAccessfactory.getCASDbAccess().validateUser(user);
        System.out.println(d == null);
        user.setUserId("ss12");
        d = CASDBAccessfactory.getCASDbAccess().validateUser(user);
        System.out.println(d == null);
    }
}
